home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Html / ^CutePage / data1.cab / IE4Gadget_Template / select.js < prev    next >
Encoding:
Text File  |  2000-05-12  |  6.7 KB  |  281 lines

  1. var globalSelect;    
  2. var q = 0;
  3. var tagid
  4.  
  5.  
  6. function LinkinitSelectBox(el,OptionStyle,sizedBorderStyle) {
  7.     LinkcopySelected(el);
  8.     
  9.     var size = el.getAttribute("size");
  10.     tagid=el.id
  11.     el.options = el.children[1].children;
  12.     el.selectedIndex = LinkfindSelected(el);    
  13.     el.remove = new Function("i", "Linkint_remove(this,i)");
  14.     el.item   = new Function("i", "return this.options[i]");
  15.     el.add    = new Function("e", "i", "Linkint_add(this, e, i)");    
  16.     el.options[el.selectedIndex].selected = true;
  17.  
  18.     dropdown = el.children[1];
  19.  
  20.     if (size != null) {
  21.         if (size > 1) {
  22.             el.size = size;
  23.             dropdown.style.zIndex = 0;
  24.             LinkinitSized(el,sizedBorderStyle);
  25.         }
  26.         else {
  27.             el.size = 1;
  28.             dropdown.style.zIndex = 99;
  29.             if (dropdown.offsetHeight > 200) {
  30.                 dropdown.style.height = "200";
  31.                 dropdown.style.overflow = "auto";
  32.             }
  33.         }
  34.     }
  35.     
  36.  
  37. }
  38.  
  39. function Linkint_remove(el,i) {
  40.     if (el.options[i] != null)
  41.         el.options[i].outerHTML = "";
  42. }
  43.  
  44. function Linkint_add(el, e, i) {
  45.     var html = "<div class='"+el.id+"option' noWrap";
  46.     if (e.value != null)
  47.         html += " value='" + e.value + "'";
  48.     if (e.style.cssText != null)
  49.         html += " style='" + e.style.cssText + "'";
  50.     html += ">";
  51.     if (e.text != null)
  52.         html += e.text;
  53.     html += "</div>"
  54.  
  55.     if ((i == null) || (i >= el.options.length))
  56.         i = el.options.length-1;
  57.  
  58.     el.options[i].insertAdjacentHTML("AfterEnd", html);
  59. }
  60.     
  61. function LinkinitSized(el,sizedBorderStyle) {
  62.     var h = 0;
  63.     el.children[0].style.display = "none";
  64.  
  65.     dropdown = el.children[1];
  66.     dropdown.style.visibility = "visible";
  67.  
  68.     if (dropdown.children.length > el.size) {
  69.         dropdown.style.overflow = "auto";
  70.         for (var i=0; i<el.size; i++) {
  71.             h += dropdown.children[i].offsetHeight;
  72.         }
  73.  
  74.         if (dropdown.style.borderWidth != null) {
  75.             dropdown.style.pixelHeight = h + 4; 
  76.         }
  77.  
  78.         else
  79.             dropdown.style.height = h;
  80.  
  81.     }
  82.  
  83.     dropdown.style.border = sizedBorderStyle;
  84.  
  85.  
  86.     el.style.height = dropdown.style.pixelHeight;
  87. }
  88.  
  89. function LinkcopySelected(el) {
  90.     var selectedIndex = LinkfindSelected(el);
  91.  
  92.     selectedCell = el.children[0].rows[0].cells[0];
  93.     selectedDiv  =     el.children[1].children[selectedIndex];
  94.     
  95.     selectedCell.innerHTML = selectedDiv.outerHTML;
  96. }
  97.  
  98. function LinkfindSelected(el) {
  99.     var selected = null;
  100.  
  101.  
  102.     ec = el.children[1].children;    
  103.     var ecl = ec.length;
  104.     
  105.     for (var i=0; i<ecl; i++) {
  106.         if (ec[i].getAttribute("selected") != null) {
  107.             if (selected == null) {    
  108.                 selected = i;
  109.             }
  110.             else
  111.                 ec[i].removeAttribute("selected");    
  112.         }
  113.     }
  114.     if (selected == null)
  115.         selected = 0;    
  116.  
  117.     return selected;
  118. }
  119.  
  120. function LinktoggleDropDown(el) {
  121.     if (el.size == 1) {
  122.         dropDown = el.children[1];
  123.         
  124.         if (dropDown.style.visibility == "")
  125.             dropDown.style.visibility = "hidden";
  126.             
  127.         if (dropDown.style.visibility == "hidden")
  128.             LinkshowDropDown(dropDown);
  129.         else
  130.             LinkhideDropDown(dropDown);
  131.     }
  132. }
  133.  
  134. function LinkoptionClick(OptionStyle) {
  135.     parel=window.event.srcElement.parentElement.parentElement.id+"option"
  136.     el = LinkgetReal(window.event.srcElement, "className", parel);
  137.  
  138.     if (el.className == parel) {
  139.         dropdown  = el.parentElement;
  140.         selectBox = dropdown.parentElement;
  141.         
  142.         oldSelected = dropdown.children[LinkfindSelected(selectBox)]
  143.  
  144.         if(oldSelected != el) {
  145.             oldSelected.removeAttribute("selected");
  146.             el.setAttribute("selected", 1);
  147.             selectBox.selectedIndex = LinkfindSelected(selectBox);
  148.         }
  149.  
  150.         if (selectBox.onchange != null) {    
  151.             if (selectBox.id != "") {        
  152.                 eval(selectBox.onchange.replace(/this/g, selectBox.id));
  153.             }
  154.             else {
  155.                 globalSelect = selectBox;
  156.                 eval(selectBox.onchange.replace(/this/g, "globalSelect"));
  157.             }
  158.         }
  159.         
  160.         if (el.backupCss != null)
  161.             el.style.cssText = el.backupCss;
  162.         LinkcopySelected(selectBox);
  163.         LinktoggleDropDown(selectBox);
  164.         LinkhighlightSelected(selectBox, true,OptionStyle);
  165.     }
  166. }
  167.  
  168. function LinkoptionOver(OptionStyle) {
  169.     parel=window.event.srcElement.parentElement.parentElement.id+"option"
  170.     var toEl = LinkgetReal(window.event.toElement, "className", parel);
  171.     var fromEl = LinkgetReal(window.event.fromElement, "className", parel);
  172.     if (toEl == fromEl) return;
  173.     var el = toEl;
  174.     
  175.     if (el.className == parel) {
  176.         if (el.backupCss == null)
  177.             el.backupCss = el.style.cssText;
  178.         LinkhighlightSelected(el.parentElement.parentElement, false,OptionStyle);
  179.         el.style.cssText = el.backupCss + "; " + OptionStyle;
  180.         this.highlighted = true;
  181.     }
  182. }
  183.  
  184. function LinkoptionOut(OptionStyle) {
  185.     parel=window.event.srcElement.parentElement.parentElement.id+"option"
  186.     var toEl = LinkgetReal(window.event.toElement, "className", parel);
  187.     var fromEl = LinkgetReal(window.event.fromElement, "className", parel);
  188.  
  189.     if (fromEl == fromEl.parentElement.children[LinkfindSelected(fromEl.parentElement.parentElement)]) {
  190.         if (toEl == null)
  191.             return;
  192.         if (toEl.className != parel)
  193.             return;
  194.     }
  195.     
  196.     if (toEl != null) {
  197.         if (toEl.className != parel) {
  198.             if (fromEl.className == parel)
  199.                 LinkhighlightSelected(fromEl.parentElement.parentElement, true,OptionStyle);
  200.         }
  201.     }
  202.     
  203.     if (toEl == fromEl) return;
  204.     var el = fromEl;
  205.  
  206.     if (el.className == parel) {
  207.         if (el.backupCss != null)
  208.             el.style.cssText = el.backupCss;
  209.     }
  210.  
  211. }
  212.  
  213. function LinkhighlightSelected(el,add,OptionStyle) {
  214.     var selectedIndex = LinkfindSelected(el);
  215.     
  216.     selected = el.children[1].children[selectedIndex];
  217.     
  218.     if (add) {
  219.         if (selected.backupCss == null)
  220.             selected.backupCss = selected.style.cssText;
  221.         selected.style.cssText = selected.backupCss + "; " + OptionStyle;
  222.     }
  223.     else if (!add) {
  224.         if (selected.backupCss != null)
  225.             selected.style.cssText = selected.backupCss;
  226.     }
  227. }
  228.  
  229. function LinkhideShownDropDowns() {
  230.     parel=tagid+"select"
  231.     var el = LinkgetReal(window.event.srcElement, "className", parel);
  232.     
  233.     var spans = document.all.tags("SPAN");
  234.     var selects = new Array();
  235.     var index = 0;
  236.     
  237.     for (var i=0; i<spans.length; i++) {
  238.         if ((spans[i].className == parel) && (spans[i] != el)) {
  239.             dropdown = spans[i].children[1];
  240.             if ((spans[i].size == 1) && (dropdown.style.visibility == "visible"))
  241.                 selects[index++] = dropdown;
  242.         }
  243.     }
  244.     
  245.     for (var j=0; j<selects.length; j++) {
  246.         LinkhideDropDown(selects[j]);
  247.     }    
  248.  
  249. }
  250.  
  251. function LinkhideDropDown(el) {
  252.     if (typeof(fade) == "function")
  253.         fade(el, false);
  254.     else
  255.         el.style.visibility = "hidden";
  256. }
  257.  
  258. function LinkshowDropDown(el) {
  259.     if (typeof(fade) == "function")
  260.         fade(el, true);
  261.     else if (typeof(swipe) == "function")
  262.         swipe(el, 2);
  263.     else
  264.         el.style.visibility = "visible";
  265. }
  266.  
  267.  
  268.  
  269. function LinkgetReal(el, type, value) {
  270.     temp = el;
  271.     while ((temp != null) && (temp.tagName != "BODY")) {
  272.         if (eval("temp." + type) == value) {
  273.             el = temp;
  274.             return el;
  275.         }
  276.         temp = temp.parentElement;
  277.     }
  278.     return el;
  279. }
  280.  
  281.